package com.shuai.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;

import com.shuai.sql.SQL;
import com.shuai.stickynote.PlantNote;
import com.shuai.stickynote.R;

import java.util.ArrayList;

public class PlantRemoviewFactory implements RemoteViewsService.RemoteViewsFactory {
    public static ArrayList<PlantNote> plants = new ArrayList<>();

    private Context context;
//    private String day;
    private String TAG = "fuck";

    public PlantRemoviewFactory(Context context, Intent intent) {
        this.context = context;
//        day = intent.getStringExtra("day");
    }

    @Override
    public void onCreate() {
        if (plants == null) plants = new ArrayList<>();
//        SQL sql = new SQL(context);
//        plants = sql.selectPlantByDay(day);
    }

    @Override
    public void onDataSetChanged() {

    }

    @Override
    public void onDestroy() {
        plants.clear();
    }

    @Override
    public int getCount() {
        return plants.size();
    }

    @Override
    public RemoteViews getViewAt(int position) {
        RemoteViews views = new RemoteViews(context.getPackageName(),
                R.layout.adapter_widget_plant_list_item);
        String content = plants.get(position).getContent();
        views.setTextViewText(R.id.adapter_widget_plant_content,content);
        return views;
    }
    @Override
    public RemoteViews getLoadingView() {
        return null;
    }

    @Override
    public int getViewTypeCount() {
        return 1;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }
}
